import org.redisson.Redisson;
import org.redisson.liveobject.resolver.UUIDGenerator;

import java.io.IOException;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;

public class Test implements InvocationHandler {

    Queue queue = new LinkedList();
    Hashtable<Integer,Integer> hashTable = new Hashtable<Integer,Integer>();
//    ConcurrentHashMap;
//    ReentrantLock;
//    ThreadLocal;

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("test --- start");
        Object o = method.invoke(args);
        System.out.println("test --- end");
        return o;
    }

    class Inner {
        public String  v1 = "Fake News";
        public String v2 = "Go ahead";
    }

    private static String GetVal() {
        try {
            return Inner.class.newInstance().v1;
        } catch (Exception e) {
            try {
                return Inner.class.getDeclaredConstructor(Test.class).newInstance((Test)null).v2;
            } catch (Exception ee) {
                ee.printStackTrace();
                return "Fake News, Go ahead";
            }
        }
    }

    static class Person{
        //两个属性值：分别代表值传递和引用传递
        private Age age;
        private String name;
        public Person(Age age,String name) {
            this.age=age;
            this.name=name;
        }
        //拷贝构造方法
        public Person(Person p) {
            this.name=p.name;
            this.age=p.age;
        }

        public void setName(String name) {
            this.name=name;
        }

        public String toString() {
            return this.name+" "+this.age;
        }
    }

    static class Age{
        private int age;
        public Age(int age) {
            this.age=age;
        }

        public void setAge(int age) {
            this.age=age;
        }

        public int getAge() {
            return this.age;
        }

        public String toString() {
            return getAge()+"";
        }
    }

    public static void main(String[] args) {
//        System.out.print(method(0));
//        short s = 1;
//        s =+ 1;
//        System.out.println(s);
//
//
//        Age a=new Age(20);
//        Person p1=new Person(a,"摇头耶稣");
//        Person p2=new Person(p1);
//        System.out.println("p1是"+p1);
//        System.out.println("p2是"+p2);
//        //修改p1的各属性值，观察p2的各属性值是否跟随变化
//        p1.setName("小傻瓜");
//        a.setAge(99);
//        System.out.println("修改后的p1是"+p1);
//        System.out.println("修改后的p2是"+p2);


//        Test test = new Test();
//        System.out.println(test.calc(10) );
//        System.out.println(test.Duplicate("cbacdcbc"));

//        Thread t = new Thread() {
//            public void run() {
//                cnn();
//            }
//        };
//        t.run();
//        System.out.print("FakeNews ");
//        System.out.print("; ");
//        t.start();
//        System.out.print("FakeNews ");

//        Map<String, Object> map = new HashMap<>();
//        String str = "没人比我更懂java";
//        StrObject obj = new StrObject("没人比我更懂java");
//        map.put("str", str);
//        map.put("obj", obj);
//
//        str = "真的没人比我更懂java";
//        System.out.printf(map.get("str").toString()+"; ");
//
//        StrObject new_obj = (StrObject) map.get("obj");
//        new_obj.setStr("真的没人比我更懂java");
//        System.out.printf(map.get("obj").toString()+"; ");

//        String s = new String(new char[] {'没','人','比','我','更','懂','j','a','v','a'});
//        String si = "没人比我更懂java";
//        System.out.println(s == si); //false
//        System.out.println(s.intern() == "没人比我更懂java");  //true
//        System.out.println(s == si.intern()); //false

//        System.out.println(GetVal());
        oneEditAway("","a");

        System.out.println("test");
//        try {
//            Thread.sleep(Integer.MAX_VALUE);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }

        System.out.println("end");

        Object a; // 还没有初始化 未分配内存
        Object b = new Object(); // b在栈中   new Object 在堆中 b的引用指向new Object()的地址

        BigDecimal bigDecimal = BigDecimal.valueOf(4.0);
        Redisson redisson;
    }

//    public static void main(String[] args) {
//
//        Integer i1 = 100;
//        Integer i2 = 100;
//        Integer i4 = Integer.valueOf(100);
//
//
//        Integer i3 = Integer.valueOf(200);
//        Integer i5 = Integer.valueOf(200);
//        Integer i6 = 400;
//        Integer i7 = 400;
//
//        int n1 = 100;
//        int n2 = 200;
//
//        System.out.println("i1 == i2 "+ (i1 == i2));
//        System.out.println("i1 == i4 "+ (i1 == i4));
//        System.out.println("i3 == i5 "+ (i3 == i5));
//        System.out.println("i6 == i7 "+ (i6 == i7));
//
//
//        System.out.println("i1 == n1 "+ (i1 == n1));
//        System.out.println("i3 == n2 "+ (i3 == n2));

    static class StrObject{
        String str;
        public StrObject(String str){
            this.str = str;
        }
        public void setStr(String str){
            this.str = str;
        }
        @Override
        public String toString() {
            return str;
        }
    }

    static void cnn() {
        System.out.print("CNN ");
    }

    public int calc(int n) {
           try {
                  n+=1;
                    if(n/0 > 0) {
                             n+=1;
                         } else {
                             n-=10;
                       }
                    return n;
                 } catch(Exception e) {
                     n++;
                 }
             n++;
             return n++;
    }


    /**
     * 字符串去重
     */
    public String Duplicate(String str) {


        // 遍历原字符串，将字符存入map
        HashMap<Character, Integer> map = new HashMap();
        for (int i = 0; i < str.length(); i++) {
            map.put(str.charAt(i), i);
        }

        // set集合 用来存储每次遍历的字符
        HashSet set = new HashSet();

        Stack<Character> stack = new Stack<>();

        for (int i = 0; i<str.length(); i++) {

            char c = str.charAt(i);

            // 如果set 中没有该字符 则进行插入
            if (!set.contains(c)) {

                // 栈非空；该字符字典序小于栈顶元素；栈顶元素不是最后一次出现在字符串中
                if (!stack.isEmpty() && c < stack.peek() && map.get(stack.peek()) > i ) {
                    // 栈中弹出栈顶元素  ；set中去除栈顶弹出的元素；
                    set.remove(stack.pop());
                }

                set.add(c);
                stack.push(c);

            }
        }

        StringBuffer s = new StringBuffer(stack.size());
        for (Character c : stack){
            s.append(c.charValue());
        }
        return s.toString();

    }



     public static boolean oneEditAway(String first, String second) {

         // first 的长度
         int len1 = first.length();
         // second的长度
         int len2 = second.length();


         // 保证 first > second
         if(len1 > len2){
             return oneEditAway(second,first);
         }

         // 长度差大于1 FALSE
         if(len2-len1 > 1){
             return false;
         }


         // 长度相同仅有一位不同
         if(len2 == len1){
         // 计数
         int count =0;
             for(int i=0; i<len1; i++){
                 if(first.charAt(i) != second.charAt(i)){
                     count+=1;
                 }
             }
             return count <=1;
         }

         int i=0 ,ofs = 0;
         while(i<len1){
             if(first.charAt(i) != second.charAt(i + ofs)){
                 if(++ofs >1){
                     return false;
                 }
             }else{
                 i+=1;
             }
         }
         return true;
     }


}
